/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.statistics.Visit;
import com.blandware.atleap.model.core.statistics.SearchCase;

import java.util.List;

/**
 * <p>DAO for statistics.</p>
 * <p><a href="StatisticsDAO.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.8 $ $Date: 2006/06/16 15:21:23 $
 */
public interface StatisticsDAO extends DAO {

    /**
     * Creates new visit.
     *
     * @param visit visit to create
     * @return created visit ID
     */
    public Long createVisit(Visit visit);

    /**
     * Updates a visit.
     *
     * @param visit visit to update
     */
    public void updateVisit(Visit visit);

    /**
     * Returns first free session number.
     *
     * @return first free session number
     */
    public Integer getFirstFreeSessionNumber();

    /**
     * Returns first free visitor number.
     *
     * @return first free visitor number
     */
    public Integer getFirstFreeVisitorNumber();

    /**
     * Retrieves filtered/sorted collection of info about most popular browsers.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: browser ID, total count
     * and unique count
     */
    public PartialCollection listTopBrowsers(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular OSes.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: OS ID, total count
     * and unique count
     */
    public PartialCollection listTopOSes(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular indexing
     * robots.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: robot ID, total count
     * and unique count
     */
    public PartialCollection listTopRobots(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: page, total count
     * and unique count
     */
    public PartialCollection listTopPages(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular content
     * resources.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: resource, total count
     * and unique count
     */
    public PartialCollection listTopContentResources(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular referrer
     * URLs.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: URL, total count
     * and unique count
     */
    public PartialCollection listTopReferrerUrls(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular referrer
     * domains.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: domain, total count
     * and unique count
     */
    public PartialCollection listTopReferrerDomains(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular entry points which
     * are pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: page ID, total count
     * and unique count
     */
    public PartialCollection listTopPagesEntryPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular entry points which
     * are NOT pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: URL, total count
     * and unique count
     */
    public PartialCollection listTopOtherEntryPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular exit points which
     * are pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: page ID, total count
     * and unique count
     */
    public PartialCollection listTopPagesExitPoints(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of most popular exit points which
     * are NOT pages.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: URL, total count
     * and unique count
     */
    public PartialCollection listTopOtherExitPoints(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular search
     * engines.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: search engine ID, total count
     * and unique count
     */
    public PartialCollection listTopSearchEngines(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular search
     * phrases.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: phrase, total count
     * and unique count
     */
    public PartialCollection listTopSearchPhrases(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular search
     * words.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopSearchWords(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular screen
     * resolutions.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of four-element arrays: width, height, total count
     * and unique count
     */
    public PartialCollection listTopScreenResolutions(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular color
     * depths.
     * For each element, count of all visits and count of unique visitors are
     * obtained. Elements are sorted by 'popularity': first on 'unique count',
     * then on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of three-element arrays: color depth, total count
     * and unique count
     */
    public PartialCollection listTopColorDepths(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular search
     * phrases in internal search engine.
     * For each element, count of all visits is obtained. Elements are sorted
     * by 'popularity':  on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of two-element arrays: phrase and total count
     */
    public PartialCollection listTopInternalSearchPhrases(QueryInfo queryInfo);

    /**
     * Retrieves filtered/sorted collection of info about most popular search
     * words in internal search engine.
     * For each element, count of all visits is obtained. Elements are sorted
     * by 'popularity':  on 'total' count.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of ObjectCountInfo instances
     */
    public PartialCollection listTopInternalSearchWords(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of visitors.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of visitors
     */
    public PartialCollection listVisitors(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of visitor sessions.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of sessions
     */
    public PartialCollection listVisitorSessions(QueryInfo queryInfo);

    /**
     * Returns filtered/sorted collection of visits.
     *
     * @param queryInfo Object that contains information about how to filter
     * and sort data
     * @return Collection of visits
     */
    public PartialCollection listVisits(QueryInfo queryInfo);

    /**
     * Returns statistics totals monthly. Array of info per year is returned;
     * each element is array of pairs per month; each pair contains total
     * number of visits and number of unique visitors.
     *
     * @return statistics totals
     */
    public List getTotalsMonthly();

    /**
     * Returns statistics totals daily. List of triads is returned: day, total
     * visits, unique visitors.
     *
     * @return statistics totals daily
     */
    public List getTotalsDaily(Integer year, Integer month);

    /**
     * Returns statistics totals hourly. List of triads is returned: hour, total
     * visits, unique visitors.
     *
     * @return statistics totals hourly
     */
    public List getTotalsHourly(Integer year, Integer month, Integer day);

    /**
     * Returns a list of visits made by a particular user.
     *
     * @param username name of user
     * @return list of visits
     */
    public List listUserVisits(String username);

    /**
     * Returns a list of visits made to a particular page.
     *
     * @param pageId ID of page
     * @return list of visits
     */
    public List listPageVisits(Long pageId);

    /**
     * Returns a list of visits made to a particular content resource.
     *
     * @param contentResourceId ID of content resource
     * @return list of visits
     */
    public List listContentResourceVisits(Long contentResourceId);

    /**
     * Retrieves a visit by its ID.
     *
     * @param visitId ID of visit to retrieve
     * @return retrieved visit
     */
    public Visit retrieveVisit(Long visitId);

    /**
     * Creates a search case.
     *
     * @param searchCase transfer object representing search case to create
     * @return ID of created search case
     */
    public Long createSearchCase(SearchCase searchCase);
}
